Bucket sort with bubble and selection sort

  • bucket sort(bin sort)
    • definition: a sorting algorithm that distribute elements into buckets based on certain criteria or rule, and sorts each bucket individually (recursively). Finally, the sorted buckets are combined to produce the final sorted array. (Bucket sort - Wikipedia)
    • time complexity: Average complexity of \(O(n+\frac{n^2}{k}+k)\) where \(k\) is the number of buckets and \(n\) is the length of sorted list. %%In our code, the complexity is \(O(max(n,k))\). ==maybe need more explanation==%%
    • space complexity: \(O(k)\) where \(k\) is the number of bucket.
  • bubble sort
    • definition: Repeatedly swaps adjacent elements if they are in the wrong order, gradually “bubbling” the largest (or smallest) element to its correct position. ([David Slide])
  • selection sort
    • definition: Repeatedly selects the smallest (or largest) element from the unsorted portion and swaps it with the first unsorted element. ([David Slide])
  • comparing time complexity: Both have \(O(n^2)\), less efficient than bucket sort.
  • space complexity: Both do not take additional space, more effective in memory usage.
  • application: Bucket Sort is ideal for sorting uniformly distributed numerical data, such as percentages, as it efficiently categorizes values into buckets for sorting, though it requires extra memory. In comparison, Bubble Sort is primarily used for educational purposes, as it demonstrates basic sorting concepts through repeated adjacent swaps. Selection Sort, while inefficient for large datasets, is useful when memory is limited and a straightforward algorithm is needed to organize small amounts of data. ==not finished==